﻿using HZH_Controls.Controls;
using HZH_Controls.Forms;
using Petroleum.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Petroleum.Tool
{
    public class ASYTool : LogHelper
    {
        /// <summary>
        /// 获取控件内的子控件值
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static List<Brick> GetControll(Control control) 
        {
            List<Brick> result = new List<Brick>() { };
            
            foreach (Control item in control.Controls)
            {
                if (item is TextBox || item is TextBoxEx || item is UCTextBoxEx)
                {
                    result.Add(new Brick(item.Name, item.Name));
                } 
            }
            return result;
        }
        /// <summary>
        /// 获取控件内的子控件值
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        //public static void SetLabControll<T>(Control panel, Control type,List<T> list)
        //{
        //    //List<Brick> result = new List<Brick>() { };
        //    int index = 0;
        //    foreach (Control item in panel.Controls)
        //    {
        //        if (item is Label || item is LinkLabel)
        //        {
        //            item.Text = list[index];
        //        }
        //    }
        //   // return result;
        //}
        public static void TextBox_KeyPress(object sender, KeyEventArgs e)
        {
            //FrmDialog.ShowDialog(this,e.KeyValue.ToString());
            MessageBox.Show(e.KeyValue.ToString());
            if (e.KeyValue < 48 && e.KeyValue>57)
            {
                e.Handled = true;
            }
        }
        public static bool IsNumeric(UCTextBoxEx input)
        {
            return Regex.IsMatch(input.InputText, @"^(\-|\+)?\d+(\.\d+)?$");
        }
        public static bool IsNumeric(string value)
        {
            
            return Regex.IsMatch(value, @"^(\-|\+)?\d+(\.\d+)?$");
        }
        public static bool IsInt(string value)
        {
            return Regex.IsMatch(value, @"^[+-]?\d*$");
        }
        public static bool IsUnsign(string value)
        {
            return Regex.IsMatch(value, @"^\d*[.]?\d*$");
        }

        public static bool isTel(string strInput)
        {
            return Regex.IsMatch(strInput, @"\d{3}-\d{8}|\d{4}-\d{7}");
        }
        //public static Image GetImage(string url)
        //{
        //    try
        //    {
        //        return Image.FromStream(WebRequest.Create(url).GetResponse().GetResponseStream());

        //    }
        //    catch
        //    {
        //        return new Bitmap(50, 50);
        //    }
        //}

    }
}
